<?
for($x=0;$x<count($PiutangTableSource);$x++){
	$SQL[] = "
	INSERT INTO $PiutangTableTarget 
	(ledger,ktrasl,nobkt , normut , nobkta , tglbkt , debtur , debnam , uraian , skada , curr , jumlah , dk , rupiah , aslref , noref, ktrled , untush ,  batcab , srt,rate)	
	SELECT DATE_FORMAT(tglbkt,'%y%m'),'003' ,NOBKT, NORMUT, NOBKTA, TGLBKT, DEBTUR, DEBNAM, URAIAN,  SKADA, if(CURR='01','IDR','USD'), JUMLAH, DK, RUPIAH, ASLREF, NOREF, KTRLED, UNTUSH, BATCAB, SRT,RUPIAH/JUMLAH AS RATE
	FROM $SourceDB.{$PiutangTableSource[$x]}
	";
}

$SQL[] ="
UPDATE $TransMMTableTarget SET curr='IDR' WHERE curr='01';
";

$SQL[] ="
UPDATE $TransMMTableTarget SET curr='USD' WHERE curr='02';
";

$SQL[] ="
UPDATE $TransMMTableTarget SET noref=insert(noref,3,0,'0') WHERE (noref like 'BB%' or noref like 'BK%' or noref like 'TB%' or noref like 'TK%' or noref like 'ND%' or noref like 'NK%' or noref like 'MM%')
";

$SQL[] ="
UPDATE $TransMMTableTarget SET nobkt=insert(nobkt,3,0,'0')
";

$SQL[] ="
UPDATE $TransMMTableTarget SET curr='IDR' WHERE curr='01';
";


$SQL[] ="
INSERT INTO  ais_memorial (ledger,ktrasl,nobkt,urut,tglbkt,skada,debtur,debnam,uraian,untush,curr,jumlah,dk,rupiah) SELECT ledger,ktrasl,nobkt,normut,tglbkt,skada,debtur,debnam,uraian,untush,curr,jumlah,dk,rupiah from ais_piutang
";

/*
$SQL[] ="
UPDATE $TransMMTableTarget SET noref=insert(noref,7,0,'0') WHERE (noref like 'BB%' or noref like 'BK%' or noref like 'TB%' or noref like 'TK%' or noref like 'ND%' or noref like 'NK%' or noref like 'MM%')
";

$SQL[] ="
UPDATE $TransMMTableTarget SET nobkt=insert(nobkt,7,0,'0')
";
*/

/*
$SQL[] ="
UPDATE $TransMMTableTarget SET noref=concat(left(noref,2),'0',right(noref,LENGTH(noref)-2)) WHERE (noref like 'BB%' or noref like 'BK%' or noref like 'TB%' or noref like 'TK%' or noref like 'ND%' or noref like 'NK%' or noref like 'MM%')
";

$SQL[] ="
UPDATE $TransMMTableTarget SET nobkt=concat(left(nobkt,2),'0',right(nobkt,LENGTH(nobkt)-2)) WHERE (nobkt like 'BB%' or nobkt like 'BK%' or nobkt like 'TB%' or nobkt like 'TK%' or nobkt like 'ND%' or nobkt like 'NK%' or nobkt like 'MM%')
";
*/


//Execute Query MEssage
for($x=0;$x<count($SQL);$x++){
	$DBConnection->dbc->query($SQL[$x]);
//	print $SQL[$x]."<br>\n"; 
	

}
?>
